# Maintainer: Ray Donnelly <mingw.android@gmail.com>

_realname=libimobiledevice
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=1.3.0
pkgrel=8
pkgdesc='A cross-platform protocol library to communicate with iOS devices (mingw-w64)'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64' 'clang32')
url='https://www.libimobiledevice.org/'
license=('spdx:LGPL-2.1-or-later')
source=(${_realname}-${pkgver}.tar.gz::"https://github.com/libimobiledevice/libimobiledevice/archive/${pkgver}.tar.gz"
        001-1.3.0-Fix-windows-build.patch
        002-1.3.0-Link-Iphlpapi.patch
        003-1.3.0-PyString_AsString-now-PyBytes_AsString.patch
        004-clang.patch::https://github.com/libimobiledevice/libimobiledevice/commit/19f9a4c37122779ad23df4180da37cbaca1e520a.patch
        005-libplist-2.3.0.patch)
depends=("${MINGW_PACKAGE_PREFIX}-libusbmuxd"
         "${MINGW_PACKAGE_PREFIX}-libplist"
         "${MINGW_PACKAGE_PREFIX}-openssl")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-autotools"
             "${MINGW_PACKAGE_PREFIX}-cython")
sha256sums=('acbfb73eabee162e64c0d9de207d71c0a5f47c40cd5ad32a5097f734328ce10a'
            'c72055c417d6fd10106793fd193c64e0147240f584c9025561cb9cd28bee112d'
            '693d2df13fd344ef67e41c7a769c12843a60a7d89a825e118a40914ed407a4fb'
            '438469e5bfce0eca723ec597ae8e97cbaca22ee548559f2d65e1fd63aba46b4b'
            'f6a5ef4500f65290d5b145bf7591e17bc3b7e420c6f7b10cf07330e076788304'
            '57fb4616c68c240aad47df52168fa30e4bf43845bfbe53df23cc412003ae64fd')

prepare() {
  cd ${srcdir}/${_realname}-${pkgver}
  # https://github.com/libimobiledevice/libimobiledevice/commit/52371bccdcb1b0fe98930e79ac2ab9bdad2700e2
  patch -p1 -i ${srcdir}/001-1.3.0-Fix-windows-build.patch
  patch -p1 -i ${srcdir}/002-1.3.0-Link-Iphlpapi.patch
  # https://github.com/libimobiledevice/libimobiledevice/commit/7044571b4f243d2fda4dd3aa491f2f279787ee19
  patch -p1 -i ${srcdir}/003-1.3.0-PyString_AsString-now-PyBytes_AsString.patch
  patch -p1 -i ${srcdir}/004-clang.patch
  # https://github.com/archlinux/svntogit-packages/blob/master/libimobiledevice/trunk/libplist-2.3.0.diff
  patch -p1 -i ${srcdir}/005-libplist-2.3.0.patch

  NOCONFIGURE=1 ./autogen.sh
}

build() {
  mkdir -p "${srcdir}"/build-${MSYSTEM} && cd "${srcdir}"/build-${MSYSTEM}

  PYTHON=${MINGW_PREFIX}/bin/python \
  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --enable-static \
    --enable-shared

  make
}

check() {
  cd "${srcdir}"/build-${MSYSTEM}
  make check
}

package() {
  cd "${srcdir}"/build-${MSYSTEM}
  make install DESTDIR="${pkgdir}"

  rm -f ${pkgdir}${MINGW_PREFIX}/lib/python*/site-packages/*.a
}
